/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            discountTypeInfo: {
                types: [],
                total: 0,
                records: 1,
                moreCondition: false,
                applyType: '',
                conditions: {
                    typeName: '',
                    applyType: '',
                    communityId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listApplyRoomDiscountTypes(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('discountType', 'listApplyRoomDiscountType', function (_param) {
                $that._listApplyRoomDiscountTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listApplyRoomDiscountTypes(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listApplyRoomDiscountTypes: function (_page, _rows) {
                $that.discountTypeInfo.conditions.page = _page;
                $that.discountTypeInfo.conditions.row = _rows;
                $that.discountTypeInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                
                let param = {
                    params: $that.discountTypeInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/applyRoomDiscount/queryApplyRoomDiscountType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.discountTypeInfo.total = _json.total;
                        $that.discountTypeInfo.records = _json.records;
                        $that.discountTypeInfo.types = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.discountTypeInfo.records,
                            dataCount: $that.discountTypeInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddApplyRoomDiscountTypeModal: function () {
                vc.emit('addApplyRoomDiscountType', 'openAddApplyRoomDiscountTypeModal', {});
            },
            _openEditApplyRoomDiscountTypeModel: function (_applyRoomDiscountType) {
                vc.emit('editApplyRoomDiscountType', 'openEditApplyRoomDiscountTypeModal', _applyRoomDiscountType);
            },
            _openDeleteApplyRoomDiscountTypeModel: function (_applyRoomDiscountType) {
                vc.emit('deleteApplyRoomDiscountType', 'openDeleteApplyRoomDiscountTypeModal', _applyRoomDiscountType);
            },
            //查询
            _queryApplyRoomDiscountTypeMethod: function () {
                $that._listApplyRoomDiscountTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetApplyRoomDiscountTypeMethod: function () {
                $that.discountTypeInfo.conditions.typeName = "";
                $that.discountTypeInfo.conditions.applyType = "";
                $that._listApplyRoomDiscountTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.discountTypeInfo.moreCondition) {
                    $that.discountTypeInfo.moreCondition = false;
                } else {
                    $that.discountTypeInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
